﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using QuanLyDuocPham.Controllers.QuanLyHeThong.DanhMuc;
using QuanLyDuocPham.Controllers.QuanLyHeThong.NhapXuat;
namespace QuanLyDuocPham.View.QuanLyHeThong.NhapXuat
{
    /// <summary>
    /// Interaction logic for DDXUAT_Edit_View.xaml
    /// </summary>
    public partial class DDXUAT_Edit_View : Window
    {
        public DDXUAT_Edit_View()
        {
            InitializeComponent();
        }
        string ma_xuat;


        public string _ma_xuat
        {
            set
            {
                ma_xuat = value;
            }
        }
        //----------------------function--------------------
        UIElement ui;
        private void hideNHAPHANG(Boolean isenable)
        {

            cmbKhachHang.IsEnabled = isenable;
            cmbKho.IsEnabled = isenable;
            cmbLoaiHD.IsEnabled = isenable;
            cmbNhanVien.IsEnabled = isenable;
            cmbNhaThuoc.IsEnabled = isenable;
            cmbQuay.IsEnabled = isenable;
            cmbTinhTrang.IsEnabled = isenable;
            txtDaTT.IsEnabled = isenable;
            chbCo_HD.IsEnabled = isenable;
            dtHanTT.IsEnabled = isenable;
            dtpNgayGiao.IsEnabled = isenable;
            dtpNgayNhap.IsEnabled = isenable;

        }
        public delegate void added();
        public added done;
        NHANVIEN_Control nvctrl = new NHANVIEN_Control();
        KHACHHANG_Control khctrl = new KHACHHANG_Control();
        DDHXUAT_Control xctrl = new DDHXUAT_Control();
        DDH_XUAT_CT_Control xctctrl = new DDH_XUAT_CT_Control();
        KHO_Control khoctrl = new KHO_Control();
        NHATHUOC_Control ntctrl = new NHATHUOC_Control();
        QUAY_Control quayctrl = new QUAY_Control();
        //-------------------------------------------------
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            xctrl.loadForm_Edit(ma_xuat,  cmbKho, cmbKhachHang, cmbNhanVien, cmbNhaThuoc, cmbQuay, dtpNgayNhap, dtpNgayGiao, cmbTinhTrang, cmbLoaiHD, chbCo_HD, chbDa_Xoa, dtHanTT, txtDaTT);
            btnCloseNHAPCT.IsEnabled = false;
            btnReEdit.IsEnabled = false;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            xctrl.updateData(ma_xuat, cmbKho, cmbKhachHang, cmbNhanVien, cmbNhaThuoc, cmbQuay, dtpNgayNhap, dtpNgayGiao, cmbTinhTrang, cmbLoaiHD, chbCo_HD, chbDa_Xoa, dtHanTT, txtDaTT);
            btnOK.IsEnabled = false;
            btnCloseNHAPCT.IsEnabled = true;
            if (done != null)
            {
                done();
            }
            hideNHAPHANG(false);
            Controllers.UC.QuanLyHeThong.NhapXuat.UC_DDHXUAT_CT_View ul = new Controllers.UC.QuanLyHeThong.NhapXuat.UC_DDHXUAT_CT_View();
            ul._ma_xuat = ma_xuat;
            ul._ma_kho = ((KHO_Get_ListResult)cmbKho.SelectedItem).MA_KHO;
            ul._is_edit = true;
            ul.Margin = new Thickness(0, 0, 0, 0);
            MainFrame.Children.Add(ul);
            ui = ul;
            btnUndo.IsEnabled = false;
            btnReEdit.IsEnabled = true;
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnUndo_Click(object sender, RoutedEventArgs e)
        {
            xctrl.loadForm_Edit(ma_xuat, cmbKho, cmbKhachHang, cmbNhanVien, cmbNhaThuoc, cmbQuay, dtpNgayNhap, dtpNgayGiao, cmbTinhTrang, cmbLoaiHD, chbCo_HD, chbDa_Xoa, dtHanTT, txtDaTT);

        }

        private void btnReEdit_Click(object sender, RoutedEventArgs e)
        {
            hideNHAPHANG(true);
            btnReEdit.IsEnabled = false;
            btnOK.IsEnabled = true;
            btnUndo.IsEnabled = true;
            btnCloseNHAPCT.IsEnabled = false;
        }

        private void btnCloseNHAPCT_Click(object sender, RoutedEventArgs e)
        {
            if (xctctrl.TongTien(ma_xuat) == decimal.Parse(txtDaTT.Text))
            {
                chbDaTToan.IsChecked = true;
            }
            else chbDaTToan.IsChecked = false;
        }

        private void txtDaTT_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (xctctrl.TongTien(ma_xuat) == decimal.Parse(txtDaTT.Text))
            {
                chbDaTToan.IsChecked = true;
            }
            else chbDaTToan.IsChecked = false;
        }

    }
}
